<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>


<body>
    <input type="text" id="iptyzm" placeholder="请输入验证码">
    <input type="text" id="yzm" readonly>
    <button>验证</button>
    <script src="moment.js"></script>
    <script>
        function days(year, month, day) {
            var dateEnd = new Date(year, month, day);
            var dateStart = new Date(year, 1, 1)
            return (dateEnd - dateStart) / 1000 / 60 / 60 / 24
        }

        function randomNumber(start, end) {
            return Math.round(Math.random() * (end - start)) + start
        }

        function randomYzm(n) {
            bStr = '';
            bStr += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            bStr += 'abcdefghijklmnopqrstuvwxyz';
            bStr += '0123456789';
            var i = 0;
            var res = ''
            while (i < n) {
                var randomIndex = randomNumber(0, bStr.length - 1);
                res += bStr[randomIndex]
                i++;
            }
            return res
        }

        var iptYzm = document.getElementById('iptyzm');
        var yzm = document.getElementById('yzm');
        console.log(yzm)
        var btn = document.querySelector('button');
        btn.onclick = function() {
            var ipt = iptYzm.value //获取用户输入的验证码
            var yzmValue = yzm.value //获取系统生成的验证码
            if (ipt.trim().toLowerCase() == yzmValue.toLowerCase()) {
                alert("验证码正确")
            } else {
                alert("你啷个搞的")
            }
        }

        yzm.value = randomYzm(4)
    </script>
</body>

</html>